import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
var _excluded = ["dataSource", "pagination"];

/**
 * Table - 菜单配置 - 列表页面表格
 * @date: 2018-7-4

 */
import React, { PureComponent } from 'react';
import { Table as AntTable } from 'antd';
import intl from 'utils/intl';
var modelPrompt = 'ciam.menuConfig.model.menuConfig';

var Table = /*#__PURE__*/function (_PureComponent) {
  _inherits(Table, _PureComponent);

  var _super = _createSuper(Table);

  function Table(props) {
    var _this;

    _classCallCheck(this, Table);

    _this = _super.call(this, props); // 方法注册

    _this.defaultTableRowKey = 'id';
    ['onCell'].forEach(function (method) {
      _this[method] = _this[method].bind(_assertThisInitialized(_this));
    });
    return _this;
  }

  _createClass(Table, [{
    key: "onCell",
    value: function onCell() {
      return {
        style: {
          overflow: 'hidden',
          maxWidth: 180,
          textOverflow: 'ellipsis',
          whiteSpace: 'nowrap'
        },
        onClick: function onClick(e) {
          var target = e.target;

          if (target.style.whiteSpace === 'normal') {
            target.style.whiteSpace = 'nowrap';
          } else {
            target.style.whiteSpace = 'normal';
          }
        }
      };
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          _this$props$dataSourc = _this$props.dataSource,
          dataSource = _this$props$dataSourc === void 0 ? [] : _this$props$dataSourc,
          pagination = _this$props.pagination,
          others = _objectWithoutProperties(_this$props, _excluded);

      var tableProps = _objectSpread({
        rowKey: this.defaultTableRowKey,
        columns: [{
          title: intl.get("".concat(modelPrompt, ".permissionCode")).d('权限编码'),
          dataIndex: 'code',
          width: 150,
          onCell: this.onCell
        }, {
          title: intl.get("".concat(modelPrompt, ".description")).d('描述'),
          dataIndex: 'description',
          width: 180,
          onCell: this.onCell
        }],
        dataSource: dataSource,
        pagination: pagination,
        bordered: true
      }, others);

      return /*#__PURE__*/React.createElement(AntTable, tableProps);
    }
  }]);

  return Table;
}(PureComponent);

export { Table as default };